package org.study.enums;

/**
 * 枚举类可以定义抽象方法，然后让每个枚举常量实现这个方法。这种技术可以实现策略模式，每个枚举常量代表一种不同的行为策略。
 * 参考 https://blog.csdn.net/MeyrlNotFound/article/details/147870300
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2025年07月16日
 */
public class OperationEnumTest {
    public static void main(String[] args) {
        Operation op = Operation.PLUS;
        double result = op.apply(3, 4);
        System.out.println(result);
    }

    public enum Operation {
        PLUS {
            @Override
            public double apply(double x, double y) {
                return x + y;
            }
        },
        MINUS {
            @Override
            public double apply(double x, double y) {
                return x - y;
            }
        },
        TIMES {
            @Override
            public double apply(double x, double y) {
                return x * y;
            }
        },
        DIVIDE {
            @Override
            public double apply(double x, double y) {
                return x / y;
            }
        };

        public abstract double apply(double x, double y);
    }
}
